<?php
class ContactController extends CController {
	const MAIL_TO = 'huiyn2009@163.com';
//	const MAIL_TO = 'adrian4ding@gmail.com';
	
	public function actionIndex() {
		$contact = new ContactForm;
		if(isset($_POST['ContactForm'])) {
			$contact->attributes = $_POST['ContactForm'];
			if($contact->validate()) {
				if( ! @sendMail(self::MAIL_TO, '张功和老师', '[huiyn.com]来自'.$contact->name.'（电话号码：'.htmlspecialchars($contact->phone).'，电子邮箱：'.htmlspecialchars($contact->email).'）的信件', nl2br(htmlspecialchars($contact->content)))) {
					$contact->addError('isSent', '发送邮件失败，请稍后再重试。');
					$contact = new ContactForm;
				}
			}
		}
		
		$this->setPageTitle('联系我们 _广州心理咨询网');
		$this->render('contact', array(
				'contact' => $contact
			)
		);
	}
}